-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a function to return the git-link itself #69
Conversation
Hi @futuro, thanks for the PR. This is definitely something that's needed. I believe my concern with the other PRs was compatibility in that the signatures and/or return value must be changed in order to have a solid function and that calling This certainly avoids that (yay) but what about the rest of the global state? For example, if you're using if for an org capture template then won't all the checks |
Hey @sshaw, I'll admit that I'm totally ignorant about global state (and emacs hacking in general), so I don't really have a good answer for this. I'll say that the function which is calling I'd welcome any pointers on what to read to understand the global state that's at play, or idiomatic design patterns for issues like this. |
Thinking about this more, @sshaw is your question about whether |
Hi @futuro, sorry for the holdup
Yes, I think that a standalone function should be used. Something like: (git-link-url file-or-buffer &optional start end remote use-branch) |
Hi @sshaw, Thanks for the super useful package! Is there a blocker for this feature to be merged? Thanks |
It does not implement a standalone version of |
I'll see if I can shake that out today. |
While I sort this out, @sshaw, I've noticed that My current thought is to have |
Hi, Thanks for getting back to this!
The default case for git-link for interactive use, i.e., get a link of/based on the current buffer's contents and cursor position. This is okay.
This is where the problem lies. If it is going to be a legit stand-alone function it must not depend on things like the current buffer, cursor position, etc... Instead of being for interactive use it should have a signature similar to that outlined here and must return the URL and not add it to the kill ring. I would say this is general principle for functions, etc...: don't depend on global state. Once we have this baseline function it can be used for all use cases, including the interactive one. Does that help? |
Though we can depend on the output of |
@sshaw after reviewing more of the code, I think I'm starting to see the way this could work. One question: what's the goal of the optional arg |
That is supposed to be the equivalent of sorts of |
Rockin, that makes sense. Another question! You'd put the remote as an optional argument, but the function can't work without a specified remote (as far as I understand it, at least). I'm thinking about moving this to be a required argument; am I missing anything? |
Ok @sshaw, this should be ready. I went ahead with making |
J/k, sorry. I need to fix a void-variable reference. Will ping you once it's solid. |
Ok, tested, and should be good to go for review @sshaw. |
Thanks a lot. I will have a looksy at or before Christmas Day 🎅🤶 |
Hi, @futuro, lookin' good. Aside from my 2 comments I would squash this PR into a single commit. Merry Christmas! 🎄 |
Hey @sshaw, thanks for the suggestions on I've just pushed up that change, and it should be ready for review. Just to clarify, are you asking me to squash all the commits in this PR, or are you saying that you're going to do a squash merge afterwards? Thanks! And Happy New Year! |
Squash all commits, please. |
84da7f4
to
26ca72c
Compare
@sshaw commits are squashed and everything should be ready to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for squashing.
I had an in-depth look now and there are a few issues. See comments.
git-link.el
Outdated
(if (bufferp file-or-buffer) | ||
(buffer-file-name file-or-buffer) | ||
file-or-buffer))) | ||
(remote-url (git-link--remote-url remote)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must check for a nil
remote-url
first, like we do here: https://github.com/sshaw/git-link/pull/69/files#diff-a86ea92b0e180064b421a637b78c7d5ae152de93c60a82136b77a6a72c90b35cL692
Otherwise we get errors when the remote does not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A case where the remote does not exist would be trying to link from a buffer that is not part of a git repo.
@@ -666,6 +666,54 @@ return (FILENAME . REVISION) otherwise nil." | |||
(git-link--remote))) | |||
|
|||
;;;###autoload | |||
(defun git-link-url (file-or-buffer remote &optional start end use-branch-p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts/issues here:
- I think we should default
remote
togit-link-default-remote
. - If the current buffer is in directory
X
but this is called like(git-link-url "/path/to/Y/foo.txt" "origin" 10)
, whereY
is a different repository root, it should return a link toY/foo.txt
's repo but now it links to something random in repoX
. - What to do with invalid line numbers, e.g., when
end
is after or equal to start, whenstart
isnil
andend
is given? Thinking we check for these cases and signal an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with items 1 and 3, but item 2 strikes me as out of scope for this PR. Specifically, my first thought for handling this is to change every function that interacts with git-link--exec
such that they can pass a buffer/directory to run from, thus isolating the side-effect of changing our working directory.
Do you see another way of achieving 2 that only impacts git-link-url
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... but item 2 strikes me as out of scope for this PR.
When calling it as a separate function it cannot depend on state of some buffer. For example, if one creates an emacs package that calls git-link-url
the call will depend on the state of some git repo outside the function call so bugs would occur. Make sense?
I agree with items 1 and 3,
Maybe 2/3 is fine? Do they togeather outweigh the bug?
Do you see another way of achieving 2 that only impacts git-link-url?
I think this is part of the reason why this function has taken so long to exist. If I remember correctly you have to change a bit more than meets the eye. It has been since Dec or so since I had a look at the code. Will have to wait to look again. But if you think you gotz a solution then add it. But if you are concerned about your time then maybe wait 'till I can have an in-depth look again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test coverage not that good. Exhibit A.
`git-link` is incredibly useful, but it doesn't return the URL it creates. This introduces a new function which does so, allowing more tooling to make use of this great feature. Wrapped up in this I did some refactoring to drop the use of `setq` internally to the function, as that defies the purely functional nature of the call. This _shouldn't_ break anything.
Closing to due lack of feedback/progress. |
git-link
is incredibly useful, but it doesn't return the URL itcreates. This introduces a new function which does so, allowing more
tooling to make use of this great feature.
This builds from the conversation in #38 and issue #37.